﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AESyouhua
{
    public  class P_AESEncryption
    {
        private static char[] alphabet = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

        public static int[,] kuozhanmiyao(string keytext)
        {
            int[,] key = KeyExpansion.GetKeyExpansion(keytext);
            return key;
        }
        public static StringBuilder P_Encryption(string mingwen, int[,] keyexp)
        {         
            int[,] cipher = Encryption.Getencryption(mingwen.ToString(), keyexp);
            StringBuilder strB = new StringBuilder();
            for (int i = 0; i < cipher.GetLength(0); i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    StringBuilder s = new StringBuilder();
                    byte[] buf = new byte[2];
                    s = SubBytes.GetStr(cipher[i, j]);
                    buf[0] = Convert.ToByte(s.ToString(0, 4), 2);
                    buf[1] = Convert.ToByte(s.ToString(4, 4), 2);
                    strB.Append(alphabet[buf[0]] + "" + alphabet[buf[1]]);
                }
            }
            return strB;
        }
    }
}
